package com.moon.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayAddOrderConfig {

    //死信部分
    @Bean
    public FanoutExchange deadLetterOrderExchange(){
        return new FanoutExchange("deadLetterOrderExchange");
    }

    @Bean
    public Queue deadLetterOrderQueue(){
        return new Queue("deadLetterOrderQueue");
    }

    @Bean
    public Binding deadLetterOrderBinding(){
        return BindingBuilder
                .bind(deadLetterOrderQueue())
                .to(deadLetterOrderExchange());
    }


    //normal部分
    @Bean
    public DirectExchange normalOrderExchange(){
        return new DirectExchange("normalOrderExchange");
    }

    //正常队列不能有消费者
    @Bean
    public Queue normalOrderQueue(){
        return QueueBuilder.durable("normalOrderQueue")
                .deadLetterExchange("deadLetterOrderExchange")
                .deadLetterRoutingKey("xxxxxx")
                .ttl(24*3600*1000)  //延迟 1 天
                .build();

    }

    @Bean
    public Binding normalBinding(){
        return BindingBuilder.bind(normalOrderQueue())
                .to(normalOrderExchange())
                .with("addOrder");

    }


}
